import { legacy_createStore as createStore, applyMiddleware, combineReducers, compose } from "redux";
import thunk from "redux-thunk";
import { persistStore, persistReducer } from "redux-persist";
import storage from 'redux-persist/lib/storage'
import autoMergeLevel2 from "redux-persist/es/stateReconciler/autoMergeLevel2";
import { Global } from "./modules/global/reducer";
import { TagList } from "./modules/tag/reducer";
import { Setting } from "./modules/setting/reducer";

//浏览器开发工具使用
// const devtool = window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__();

const reducer = combineReducers({
    Global,
    TagList,
    Setting
})

//持久化存储
const persistConfig: any = {
    key: 'root',
    storage: storage,
    stateReconciler: autoMergeLevel2,
    blacklist: ['tagList'],//不会被持久化
}
const sitePersistReducer = persistReducer(persistConfig, reducer);
const store = createStore(sitePersistReducer, compose(applyMiddleware(thunk)));
// const store = createStore(sitePersistReducer, compose(applyMiddleware(thunk), devtool));
export const persistor = persistStore(store);
export default store;
